/*
 * Copyright 2020-2021 redragon-erp/赤龙ERP
 * Author redragon/dongbin
 * This file is part of redragon-erp/赤龙ERP.

 * 赤龙ERP官方声明：
 * (1)赤龙ERP的知识产权归软件著作权人所有
 * (2)未经著作权人授权，不得将赤龙ERP用于任何形式的商业用途
 * (3)对侵权的组织或个人，著作权人将保留诉诸法律的权利

 * 赤龙ERP官网详见 <https://www.redragon-erp.com>
 * 赤龙ERP仓库详见 <https://gitee.com/redragon/redragon-erp> 
 * 如遇任何问题，请与著作权人联系
 */
package com.erp.oa.notice.dao.hibernate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.redragon.framework.annotation.Cache;
import org.redragon.framework.annotation.Permissions;
import org.redragon.framework.annotation.Permissions.PermissionType;
import org.redragon.framework.annotation.SqlParam;
import org.redragon.framework.hibernate.DaoSupport;
import org.redragon.framework.hibernate.model.Pages;
import org.redragon.framework.util.DaoCRUDUtil;
import com.erp.oa.notice.dao.SysNoticeRecordDao;
import com.erp.oa.notice.dao.model.SysNoticeRecord;
import com.erp.oa.notice.dao.model.SysNoticeRecordCO;

@Repository
public class SysNoticeRecordDaoImpl implements SysNoticeRecordDao{ 

    //注入DaoSupport工具类
    @Autowired
    private DaoSupport daoSupport;
    
    @Override
    public void insertDataObject(SysNoticeRecord obj) {
        this.daoSupport.insertDataTransaction(obj);
    }

    @Override
    public void updateDataObject(SysNoticeRecord obj) {
        this.daoSupport.updateDataTransaction(obj);
    }
    
    @Override
    public void insertOrUpdateDataObject(SysNoticeRecord obj) {
        this.daoSupport.insertOrUpdateDataTransaction(obj);
    }

    @Override
    public void deleteDataObject(SysNoticeRecord obj) {
        this.daoSupport.deleteDataTransactionJPA(obj);
    }

    @Override
    public List<SysNoticeRecord> getDataObjects() {
        return this.daoSupport.getDataAllObject(SysNoticeRecord.class);
    }

    @Override
    public SysNoticeRecord getDataObject(int id) {
        return (SysNoticeRecord)this.daoSupport.getDataObject(SysNoticeRecord.class, id);
    }
    
    @Override
    public SysNoticeRecord getDataObject(String code) {
        return null;
    }
    
    @Override
    public List<SysNoticeRecord> getDataObjects(SysNoticeRecordCO paramObj) {
        String sql = "select c.* from sys_notice_record c where 1=1";
        
        Map<String, Object> args = new HashMap<String, Object>();
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "noticeCode", "and c.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "businessType", "and c.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "title", "and c.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "content", "and c.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "publishPerson", "and c.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "readFlag", "and c.", args);
        sql = sql + " order by c.record_id desc";
        
        Map<String, Class<?>> entity = new HashMap<String, Class<?>>();
        entity.put("c", SysNoticeRecord.class);
        
        return this.daoSupport.selectDataSql(sql, entity, args);
    }
    
    @Override
    public List<SysNoticeRecord> getDataObjects(Pages pages) {
        return null;
    }
    
    @Override
    public List<SysNoticeRecord> getDataObjects(Pages pages, SysNoticeRecordCO paramObj) {
        String sql = "select c.* from sys_notice_record c where 1=1";
        
        Map<String, Object> args = new HashMap<String, Object>();
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "noticeCode", "and c.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "businessType", "and c.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "title", "and c.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "content", "and c.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "publishPerson", "and c.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "readFlag", "and c.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "createdBy", "and c.", args);
        sql = sql + " order by c.record_id desc";
        
        Map<String, Class<?>> entity = new HashMap<String, Class<?>>();
        entity.put("c", SysNoticeRecord.class);
        
        return this.daoSupport.getDataSqlByPage(sql, entity, args, pages);
    }

    @Override
    public List<Map<String, Object>> getDataObjectsArray(Pages pages, SysNoticeRecordCO paramObj) {
        return null;
    }
    
    @Override
    @Permissions(PermissionType.DATA_AUTH)
    public List<SysNoticeRecord> getDataObjectsForDataAuth(@SqlParam String dataAuthSQL, Pages pages, SysNoticeRecordCO paramObj) {
        return null;
    }
    
    @Override
    public void updateSysNoticeRecordForReadFlag(Integer recordId) {
        String sql = "update sys_notice_record set read_flag = 'Y' where record_id = :recordId";
        
        Map<String, Object> args = new HashMap<String, Object>();
        args.put("recordId", recordId);
        
        this.daoSupport.executeSQLTransaction(sql, args);
    }

    @Override
    public List<SysNoticeRecord> getDataObjectsLimit(Pages pages, SysNoticeRecordCO paramObj) {
        String sql = "select c.* from sys_notice_record c where 1=1";

        Map<String, Object> args = new HashMap<String, Object>();
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "noticeCode", "and c.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "businessType", "and c.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "title", "and c.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "content", "and c.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "publishPerson", "and c.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "readFlag", "and c.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "createdBy", "and c.", args);
        sql = sql + " order by c.record_id desc";

        Map<String, Class<?>> entity = new HashMap<String, Class<?>>();
        entity.put("c", SysNoticeRecord.class);

        return this.daoSupport.selectDataSql(sql, entity, args);
    }

}
